import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:verse_systems/commom/models/language_model.dart';
import 'package:verse_systems/pages/mine/mine_control.dart';
import 'package:verse_systems/res/colors.dart';
import 'package:verse_systems/widgets/drawer_appbar.dart';

class MieLanguagesSet extends StatefulWidget {
  const MieLanguagesSet({super.key});

  @override
  State<MieLanguagesSet> createState() => _MieLanguagesSetState();
}

class _MieLanguagesSetState extends State<MieLanguagesSet> {
  final control = Get.find<MineControl>();
  final state = Get.find<MineControl>().state;

  @override
  void initState() {
    super.initState();
    control.getLanguagesInfo();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: DrawerAppbar(
          title: "languages_set".tr,
          actions: <Widget>[
            IconButton(
                icon: Text(
                  "languages_save".tr,
                  style: TextStyle(
                      fontSize: 16,
                      color: Colours.drawer_text_color,
                      fontWeight: FontWeight.w500),
                ),
                onPressed: control.saveLanguage)
          ],
        ),
        body: GetBuilder<MineControl>(
            init: control,
            builder: (_) {
              return ListView.separated(
                padding: EdgeInsets.symmetric(vertical: 10.w),
                itemCount: state.language.length,
                separatorBuilder: (BuildContext context, int index) {
                  return const Divider(
                    height: 1,
                    thickness: 1,
                    color: Color(0xffeff1f4),
                  );
                },
                itemBuilder: (BuildContext context, int index) {
                  LanguageModel model = state.language[index];
                  return InkWell(
                    onTap: (){
                      control.checkLanguage(index: index);
                    },
                    child: Container(
                      height: 50.w,
                      padding: EdgeInsets.symmetric(horizontal: 25.w),
                      color: Colours.app_main_color,
                      child: Row(
                        mainAxisAlignment :MainAxisAlignment.spaceBetween,
                        children: [
                          Text(
                            model.language ?? "",
                            style: TextStyle(
                              fontSize: 16.sp,
                              fontWeight: FontWeight.normal,
                              color: Colours.drawer_text_color,
                            ),
                          ),
                          Icon(
                            Icons.check,
                            color: model.language_chosen == "true"
                                ? Colours.app_main_background_color
                                : Colours.app_main_color,
                            size: 18.w,
                          ),
                        ],
                      ),
                      // color: Colors.orange,
                    ),
                  );
                },
              );
            }));
  }
}
